import {
  queryWithdrawBill,
  getUserBankCardWithdraw,
} from '../../services/order/api';


export default {
  namespace: 'totalList',

  state: {

    loading: true,

    totalListData: {
      list: [],
      pagination:{}
    },

    userBankCardData: {
      list: [],
      pagination:{}
    },
    
  },

  effects: {

    *fetchQueryWithdrawBill({payload,callback}, { call, put }) {
      const response = yield call(queryWithdrawBill, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: { 
            totalListData: {
              list: response.data.records,
              pagination: {
                current: response.data.current,
                total: response.data.total,
                size: response.data.size,
              }
            }
          },
        });
      }
      if (callback && response) callback(response);
    },

    *fetchGetUserBankCardWithdraw({payload,callback}, { call, put }) {
      const response = yield call(getUserBankCardWithdraw, payload);
      if (response && response.code == 200) {
        yield put({
          type: 'save',
          payload: { 
            userBankCardData: response.data
          },
        });
      }
      if (callback && response) callback(response);
    },
    
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },

};
